package config;

import lombok.Data;

import java.io.Serializable;

/**
 * @author : GuoFei
 * @date : 2018/11/19 11:19
 */
@Data
public class MyResult<T> implements Serializable {

    private static final long serialVersionUID = 3293082L;

    private Integer code;

    private T data;

    private String message;

    public MyResult(Integer code, T data, String message) {
        this.code = code;
        this.data = data;
        this.message = message;
    }

    public static <T> MyResult success(){
        return success(null);
    }
    public static <T> MyResult success(T data){
        return success(data, 200);
    }
    public static <T> MyResult success(T data,Integer code){
        return success( data, code,"操作成功");
    }
    public static <T> MyResult success(T data,String message){
        return success( data, 200,message);
    }
    public static <T> MyResult success(T data,Integer code,String message){
        return new MyResult(code, data, message);
    }

    public static <T> MyResult error(String message){
        return new MyResult(500,null,message);
    }

    public static <T> MyResult error(){
        return error("发生故障");
    }
    @Override
    public String toString() {
        return "MyResult{" +
                "code=" + code +
                ", data=" + data +
                ", message='" + message + '\'' +
                '}';
    }
}
